var e = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), t = require("../../../@babel/runtime/helpers/asyncToGenerator"), a = require("../../../@babel/runtime/helpers/createForOfIteratorHelper"), o = require("../../../mycomponent/payKeyboard/PayKeyboardAsync.js"), n = require("../../../mycomponent/yz_pay/yz_pay"), r = getApp();

Component({
    behaviors: [ n ],
    options: {
        styleIsolation: "isolated"
    },
    properties: {
        overlayShow: {
            type: Boolean,
            value: !1
        },
        newBlindBoxData: {
            type: null,
            value: {}
        }
    },
    lifetimes: {
        attached: function() {
            this.getOpenData();
        }
    },
    data: {
        postageShow: !1,
        integralShow: !1,
        actionSheetShow: !1,
        btnData: [],
        allData: {},
        postageNum: "",
        isDeliverGoods: !0,
        payKeyboardShow: !1
    },
    methods: {
        getOpenData: function() {
            var e = this;
            r._postNetWork({
                url: r.getNetAddresss(this.data.newBlindBoxData.api),
                data: {
                    order_id: this.data.newBlindBoxData.order_id
                },
                success: function(t) {
                    var a = t.data;
                    a.result ? e.setData({
                        allData: a.data
                    }) : wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        },
        close: function() {
            this.triggerEvent("issueGoodsClose", !1);
        },
        clickWant: function() {
            this.data.allData.canBuy && (this.data.allData.need_freight ? this.getpPstageData() : this.data.isDeliverGoods && this.deliverGoods());
        },
        deliverGoods: function() {
            var e = this;
            r._postNetWork({
                url: r.getNetAddresss("plugin.new-blind-box.frontend.activity.buy-blind-box"),
                data: {
                    order_id: this.data.newBlindBoxData.order_id
                },
                success: function(t) {
                    var a = t.data;
                    a.result ? (wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    }), e.setData({
                        overlayShow: !1,
                        isDeliverGoods: !1
                    }), wx.navigateTo({
                        url: "/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=newBindBox&title=我的盲盒"
                    })) : wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        },
        getpPstageData: function() {
            var e = this;
            r._postNetWork({
                url: r.getNetAddresss("plugin.new-blind-box.frontend.goods-buy.index"),
                data: {
                    activity_order_id: this.data.newBlindBoxData.order_id
                },
                success: function(t) {
                    var o = t.data;
                    if (o.result) {
                        var n, r = a(o.data.amount_items);
                        try {
                            for (r.s(); !(n = r.n()).done; ) {
                                var s = n.value;
                                "total_goods_price" == s.code && e.setData({
                                    postageNum: s.amount
                                });
                            }
                        } catch (e) {
                            r.e(e);
                        } finally {
                            r.f();
                        }
                        e.setData({
                            postageShow: !0
                        });
                    } else wx.showToast({
                        icon: "none",
                        title: o.msg,
                        duration: 1500
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        },
        clickClosePostage: function() {
            this.setData({
                postageShow: !1
            });
        },
        exchange: function() {
            this.setData({
                integralShow: !0
            });
        },
        cancal: function() {
            this.setData({
                integralShow: !1
            });
        },
        clickPay: function() {
            var e = this;
            r._postNetWork({
                url: r.getNetAddresss("plugin.new-blind-box.frontend.create.index"),
                data: {
                    activity_order_id: this.data.newBlindBoxData.order_id
                },
                success: function(t) {
                    var a = t.data;
                    1 == a.result ? e.getPayData(a.data.order_ids) : wx.showToast({
                        title: a.msg,
                        duration: 1e3,
                        icon: "none"
                    });
                }
            });
        },
        getPayData: function(e) {
            var t = this;
            r._postNetWork({
                url: r.getNetAddresss("order.merge-pay"),
                data: {
                    order_ids: e
                },
                success: function(e) {
                    var a = e.data;
                    1 == a.result ? (t.setData({
                        btnData: a.data.buttons,
                        actionSheetShow: !0,
                        order_sn: a.data.order_pay.pay_sn
                    }), t.data.order_pay_id = a.data.order_pay.id) : wx.showToast({
                        title: a.msg,
                        duration: 1e3,
                        icon: "none"
                    });
                }
            });
        },
        rewardPayCancelBtn: function() {
            this.setData({
                actionSheetShow: !1
            });
        },
        exchangeIntegral: function() {
            var e = this;
            r._postNetWork({
                url: r.getNetAddresss("plugin.new-blind-box.frontend.activity.exchange"),
                data: {
                    order_id: this.data.newBlindBoxData.order_id
                },
                success: function(t) {
                    var a = t.data;
                    1 == a.result ? (wx.showToast({
                        title: a.msg,
                        duration: 1e3,
                        icon: "none"
                    }), e.setData({
                        integralShow: !1,
                        overlayShow: !1
                    }), wx.navigateTo({
                        url: "/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=newBindBox&title=我的盲盒"
                    })) : wx.showToast({
                        title: a.msg,
                        duration: 1e3,
                        icon: "none"
                    });
                }
            });
        },
        payPost: function(a) {
            var o = this;
            return t(e.default.mark(function t() {
                var n, r, s;
                return e.default.wrap(function(e) {
                    for (;;) switch (e.prev = e.next) {
                      case 0:
                        if (n = a.currentTarget.dataset.info.value, !(r = a.currentTarget.dataset.info).need_password) {
                            e.next = 9;
                            break;
                        }
                        return e.next = 5, o.getPayKeyboardPassword();

                      case 5:
                        s = e.sent, o.getVerifyPassword(s), e.next = 10;
                        break;

                      case 9:
                        o.handlePay(r, n);

                      case 10:
                      case "end":
                        return e.stop();
                    }
                }, t);
            }))();
        },
        getVerifyPassword: function(e) {
            var t = this, a = r.getNetAddresss("payment.password.check");
            a += "&password=" + e, r._getNetWork({
                url: a,
                success: function(a) {
                    var o = a.data;
                    1 == o.result ? t.balancePay(e) : wx.showModal({
                        title: "提示",
                        content: o.msg,
                        success: function(e) {
                            e.confirm ? 2001 == o.data.code || (2002 == o.data.code ? wx.navigateTo({
                                url: "/packageA/member/set_balance_password/set_balance_password"
                            }) : o.data.code) : e.cancel && (2001 == o.data.code || 2002 == o.data.code || o.data.code);
                        }
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        },
        payKeyboardComplete: function(e) {
            o.payKeyboardAsync.complete(e.detail);
        },
        getPayKeyboardPassword: function() {
            return this.setData({
                payKeyboardShow: !0
            }), new Promise(function(e, t) {
                o.payKeyboardAsync.addCompleteFn(function(t) {
                    e(t);
                });
            });
        },
        payKeyboardClose: function() {
            this.setData({
                payKeyboardShow: !1
            });
        }
    }
});